package com.wangp.mywrite.coding;

/**
 * @description: 1138. 字母板上的路径
 * @author tooStronger
 * @date 2023/2/12
 */
public class AlphabetBoardPath {

    private static final char[][] ALPHABET = new char[][]{
            {'a', 'b', 'c', 'd', 'e'},
            {'f', 'g', 'h', 'i', 'j'},
            {'k', 'l', 'm', 'n', 'o'},
            {'p', 'q', 'r', 's', 't'},
            {'u', 'v', 'w', 'x', 'y'},
            {'z'},
    };

    public String alphabetBoardPath(String target) {
        int row = 0;
        int col = 0;

        StringBuilder res = new StringBuilder();
        for (char c : target.toCharArray()) {
            int curRow = (c - 'a') / 5;
            int curCol = (c - 'a') % 5;

            if (row > curRow) {
                for (int i = 0; i < (row - curRow); i++) {
                    res.append("U");
                }
            }
            if(col > curCol){
                for (int i = 0; i < (col - curCol); i++) {
                    res.append("L");
                }
            }
            if(row < curRow){
                for (int i = 0; i < (curRow - row); i++) {
                    res.append("D");
                }
            }
            if(col < curCol){
                for (int i = 0; i < (curCol - col); i++) {
                    res.append("R");
                }
            }
            row = curRow;
            col = curCol;
            res.append("!");
        }
        return res.toString();
    }

    public static void main(String[] args) {
//        System.out.println(new AlphabetBoardPath().alphabetBoardPath("leet"));
//        System.out.println(new AlphabetBoardPath().alphabetBoardPath("zdz"));
        System.out.println(new AlphabetBoardPath().alphabetBoardPath("zb"));
    }
}
